

/**
 * extend context
 */
module.exports = {
  jsonPage(data = {}) {
    // const obj = {
    //   [this.config('errnoField')]: 0,
    //   [this.config('errmsgField')]: message,
    //   data
    // };

    data.code=0;
    data.msg="";
    this.type = this.config('jsonContentType');
    this.body = data;
    return false;
  },
  jsonData(data) {
    const obj = {
      code: 0,
      msg:'',
      data
    };

    this.type = this.config('jsonContentType');
    this.body = obj;
    return false;
  },

   urlParse  (url) {
    //let url = window.location.search;
    let obj = {};
    let reg = /[?&][^?&]+=[^?&]+/g;
    let arr = url.match(reg);
    // ['?id=12345','&a=b']
    if (arr) {
      arr.forEach((item) => {
        let tempArr = item.substr(1).split('=');
        let key = decodeURIComponent(tempArr[0]);
        let val = decodeURIComponent(tempArr[1]);
        obj[key] = val
      })
    }
    return obj
  }

};
